package kg.aibek.dc;

import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Silinecek {

	public static void main(String[] args) {
		FileInputStream fis;
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();

		try {
			fis = new FileInputStream("/home/aibek/Desktop/DC/assignment2/test2/kafka_trial.txt");

			Reader reader = new InputStreamReader(fis);

			int r = 0;
			while ((r = reader.read()) != -1) {
				if (r >= 65 && r <= 90) {
					r += 32;
				}
				if (!map.containsKey(r)) {
					map.put(r, 0);
				}
				map.put(r, map.get(r) + 1);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		System.out.println("Symbol count = " + map.size());
		int counter = 0;
		int[] a = new int[map.size()];
		int j = 0;
		for (int i : map.keySet()) {
			System.out.println("code = " + i + " char = " + (char) i + " count " + map.get(i));
			counter += map.get(i);
			a[j++] = i;
		}

		System.out.println("Toplam byte sayisi = " + counter);

		Arrays.sort(a);
		for (int i = 0; i < a.length; i++) {
			System.out.println("map.put(" + a[i] + "," + i + ");");
		}
	}
}
